package cn.lizemin.sheduledtaskspringboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.DateFormat;
import java.util.Date;
@EnableAsync
@EnableScheduling
@SpringBootApplication
public class SheduledtaskSpringbootApplication {

    public static void main(String[] args) {
        SpringApplication.run(SheduledtaskSpringbootApplication.class, args);
    }

    /**
     * 每分钟提醒一次
     */
    @Async
    @Scheduled(fixedRate = 1000 * 60)
//    @Scheduled(cron = "0 0/30 9-22 * * ?")
    public void play() throws InterruptedException {
        System.out.println("线程" + Thread.currentThread().getName());
//        Thread.sleep(3000);
        System.out.println("打网球" + DateFormat.getDateTimeInstance().format(new Date()));

    }

    /**
     * 每秒提醒一次
     */
    @Async
    @Scheduled(fixedRate = 1000)
//    @Scheduled(cron = "0 0 9-22/4 * * ?")
    public void say(){
        System.out.println("线程" + Thread.currentThread().getName());
        System.out.println("聊天" + DateFormat.getDateTimeInstance().format(new Date()));
    }

}
